MODULE crc; (* 06-Nov-88. (c) KRONOS *)

FROM StdIO      IMPORT  print, Read;
FROM Edit       IMPORT  ReadString;
FROM Image      IMPORT  GetNum;

VAR rg: BITSET;

CONST c00={0..2,4,6,8..10,15};

PROCEDURE back;
  VAR a,b: BOOLEAN; r,c: BITSET; i: INTEGER;
BEGIN
  c:=c00;
  r:={};
  FOR i:=0 TO 15 DO
    r:=(r-{0})>>1;
    b:=ODD(ORD(3 IN r)+ORD(10 IN r)+ORD(15 IN r));
    IF b#(i IN c) THEN INCL(r,15) END;
  END;
  FOR i:=0 TO 15 DO
    a:=0 IN r;
    r:=(r-{0})>>1;
    b:=ODD(ORD(3 IN r)+ORD(10 IN r)+ORD(15 IN r));
    IF b#a  THEN INCL(r,15) END;
  END;
  rg:=r;
END back;

VAR r,n,m: BITSET;
    s: ARRAY [0..9] OF CHAR;
    i,q: INTEGER;
    b: BOOLEAN;
    cnt: INTEGER;
    l: INTEGER;

BEGIN
  FOR l:=0 TO 16 DO
    back;
    (*
    ReadString('> ',s);
    i:=GetNum(s,n);
    *)
    n:={l}*{0..15};
    print('%$16i  ',n);
    FOR i:=15 TO 0 BY -1 DO
      b:=ODD(ORD(3 IN rg)+ORD(10 IN rg)+ORD(15 IN rg)+ORD(i IN n));
      rg:=BITSET(rg<<1)*{1..15};
      IF b THEN INCL(rg,0) END;
    END;

    m:={}; r:=rg;
    FOR i:=15 TO 0 BY -1 DO
      b:=ODD(ORD(3 IN r)+ORD(10 IN r)+ORD(15 IN r));
      IF b THEN INCL(m,i) END;
      r:=BITSET(r<<1)*{1..15};
    END;
    print('  %$16i  %$16i\n',m,BITSET(m)/c00);
  END;
END crc.
0000000000000001    1001011101110110  0001000000100001
0000000000000010    1010011100010101  0010000001000010
0000000000000100    1100011111010011  0100000010000100
0000000000001000    0000011001011111  1000000100001000
0000000000010000    1001010101100110  0001001000110001
0000000000100000    1010001100110101  0010010001100010
0000000001000000    1100111110010011  0100100011000100
0000000010000000    0001011011011111  1001000110001000
0000000100000000    1011010001100110  0011001100110001
0000001000000000    1110000100110101  0110011001100010
0000010000000000    0100101110010011  1100110011000100
0000100000000000    0000111011111110  1000100110101001
0001000000000000    1000010000100100  0000001101110011
0010000000000000    1000000110110001  0000011011100110
0100000000000000    1000101010011011  0000110111001100
1000000000000000    1001110011001111  0001101110011000
0000000000000000    1000011101010111  0000000000000000
